﻿Namespace form
    Public Class InsertOrUpdateBase

        Enum 模式型
            添加
            修正
        End Enum

        Private _参数列表 As New Hashtable
        Public Property 参数列表() As Hashtable
            Get
                Return _参数列表
            End Get
            Set(ByVal value As Hashtable)
                _参数列表 = value
            End Set
        End Property

        Private _更新成功 As Boolean = False
        Public Property 更新成功() As Boolean
            Get
                Return _更新成功
            End Get
            Set(ByVal value As Boolean)
                _更新成功 = value
            End Set
        End Property

        Private _插入成功 As Boolean = False
        Public Property 插入成功() As Boolean
            Get
                Return _插入成功
            End Get
            Set(ByVal value As Boolean)
                _插入成功 = value
            End Set
        End Property
#Region "增加模式"
        Private _模式 As 模式型 = 模式型.添加
        Public Property 模式() As 模式型
            Get
                Return _模式
            End Get
            Set(ByVal value As 模式型)
                _模式 = value
            End Set
        End Property
#End Region

#Region "插入按钮事件"

        '在子窗体重载 做非空CHECK
        Public Overridable Function DoAddCheck() As Boolean
            DoAddCheck = True
        End Function

        '在子窗体重载 真正插入事件
        Public Overridable Function DoInsert() As Boolean
            DoInsert = True
        End Function

        '有的时候要做存在CHECK
        Public Overridable Function DoAddExist() As Boolean
            DoAddExist = True
        End Function

        '在子窗体重载 做非空CHECK
        Public Overridable Function DoUpdateCheck() As Boolean
            DoUpdateCheck = True
        End Function

        '在子窗体重载 真正更新事件
        Public Overridable Function DoUpdateExist() As Boolean
            DoUpdateExist = True
        End Function

        '有的时候要做存在CHECK
        Public Overridable Function DoUpdate() As Boolean
            DoUpdate = True
        End Function

        Public Sub btnInsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsert.Click
            If 模式 = 模式型.添加 Then
                '必须进行非空CHECK
                If DoAddCheck() = False Then Exit Sub
                If DoAddExist() = False Then Exit Sub
                If DoInsert() = False Then Exit Sub
            Else
                '必须进行非空CHECK
                If DoUpdateCheck() = False Then Exit Sub
                If DoUpdateExist() = False Then Exit Sub
                If DoUpdate() = False Then Exit Sub
            End If
        End Sub

#End Region

#Region "退出按钮事件"
        Public Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click

            DoClose()

        End Sub

        Public Overridable Sub DoClose()

            Me.Close()

        End Sub
#End Region

#Region "窗体初始化"
        Private Sub InsertOrUpdate_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

            If DesignMode = False Then
                If 模式 = 模式型.添加 Then
                    InitAdd()
                Else
                    InitUpdate()
                End If
            End If

        End Sub

#End Region

#Region "追加的重载"

        Public Overridable Sub InitAdd()

        End Sub

#End Region

#Region "更新的重载"

        Public Overridable Sub InitUpdate()
            Me.btnInsert.Text = "更新"
        End Sub

#End Region

    End Class
End Namespace
